
local zhaogu = fk.CreateSkill {
  name = "lingling__zhaogu",
}

Fk:loadTranslationTable{
  ["lingling__zhaogu"] = "照骨",
  [":lingling__zhaogu"] = "当你死亡后，你可以令一名角色本局：回合结束时弃置X张牌（X为你本回合开始时的体力值），不足则失去1点体力。",

  ["#lingling__zhaogu-choose"] = "照骨：令一名角色本局回合结束时需弃%arg张牌",
  ["@lingling__zhaogu"] = "照骨",
}

zhaogu:addEffect(fk.Deathed, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhaogu.name, false, true) and
      player:getMark("lingling__zhaogu-turn") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      skill_name = zhaogu.name,
      min_num = 1,
      max_num = 1,
      targets = room.alive_players,
      prompt = "#lingling__zhaogu-choose:::"..player:getMark("lingling__zhaogu-turn"),
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:setPlayerMark(to, "@lingling__zhaogu", player:getMark("lingling__zhaogu-turn"))
  end,
})

zhaogu:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(zhaogu.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "lingling__zhaogu-turn", player.hp)
  end,
})

zhaogu:addEffect(fk.TurnEnd, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("@lingling__zhaogu") > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = player:getMark("@lingling__zhaogu")
    local cards = room:askToDiscard(player, {
      min_num = n,
      max_num = n,
      include_equip = true,
      skill_name = zhaogu.name,
      cancelable = false,
    })
    if #cards < n and not player.dead then
      room:loseHp(player, 1, zhaogu.name)
    end
  end,
})

return zhaogu
